package com.komlin.msgpush.huaweipushmsg;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import com.huawei.hms.support.api.push.PushReceiver;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by AdministratorZJ
 * on 2019/11/6.
 */
public class HuaWeiRevicer extends PushReceiver {
    @Override
    public void onEvent(final Context context, Event event, Bundle extras) {
      /*  String customize = extras.getString("pushMsg");
        Log.e("TAG11", "推送：onEvent");
        try {
            JSONArray jsonArray = new JSONArray(customize);
            JSONObject jsonObject = (JSONObject) jsonArray.get(0);
            String type = jsonObject.getString("type");
            String data = jsonObject.getString("data");
            JSONObject object = new JSONObject(data);
            Log.e("TAG11", "点击1" + type);
            final Intent intent = new Intent();
            //0校园公告1班级公告2校园通知3班级通知4问卷调查
            if ("0".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                intent.putExtra("flag", 2).putExtra("title", "校园公告").putExtra("type", 1);
            } else if ("1".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                intent.putExtra("flag", 2).putExtra("title", "班级公告").putExtra("type", 2);
            } else if ("2".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                intent.putExtra("flag", 1).putExtra("title", "校园通知").putExtra("type", 2);
            } else if ("3".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                intent.putExtra("flag", 1).putExtra("title", "班级通知").putExtra("type", 3);
            } else if ("4".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                intent.putExtra("flag", 4).putExtra("title", "问卷调查").putExtra("type", 2);
            } else if ("5".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.new_leave.ApplyForLeaveListActivity"));
                intent.putExtra("title", "我的请假");
            } else if ("6".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveStudentActivity"));
                intent.putExtra("title", "批学生假");
            } else if ("7".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveTeachersActivity"));
                intent.putExtra("title", "批假初审").putExtra("type", 1);
            } else if ("8".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveTeachersActivity"));
                intent.putExtra("title", "批假终审").putExtra("type", 2);
            } else if ("9".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.is_on_duty.DutyCalendarActivity"));
            } else if ("10".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.trusteeship.TrusteeshipActivity"));
            } else if ("11".equals(type)) {
                String classID = object.getString("classID");
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.bed.BedroomMsgActivity"));
                intent.putExtra("classId", classID);
            } else if ("12".equals(type)) {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.visitors.VisitorsListActivity"));
            } else if ("13".equals(type)) {
                //家长留言
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.leave_message.LeaveMessageTeacherActivity"));
            } else if ("14".equals(type)) {
                //学生留言
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.leave_message.LeaveMessageStudentActivity"));
            } else if ("15".equals(type)) {
                //教师带队 com.komlin.commonedition.ui.lead_the_tean
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lead_the_tean.TeachersLeadTheTeamActivity"));
            } else if ("16".equals(type)) {
                //待处理保修
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.matters.MattersListActivity"));
            } else if ("17".equals(type)) {
                //安全巡查 com.komlin.commonedition.ui.safety_patrol
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.safety_patrol.SafetyPatrolActivity"));
            } else if ("18".equals(type)) {
                //代换课申请 com.komlin.commonedition.ui.safety_patrol
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lesson_change.LessonChangeListActivity"));
            } else if ("19".equals(type)) {
                //开发者邀请 com.komlin.commonedition.ui.safety_patrol
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lesson_change.LessonChangeInviteActivity"));
            } else {
                intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.MainActivity"));
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setAction("android.intent.action.VIEW");
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    context.startActivity(intent);
                }
            }, 1000);
        } catch (JSONException e) {
            e.printStackTrace();
        }*/
        super.onEvent(context, event, extras);
    }

    @Override
    public boolean onPushMsg(Context context, byte[] msgBytes, Bundle extras) {
        Log.e("TAG11", "推送：onPushMsg");
        try {
            //开发者可以自己解析消息内容，然后做相应的处理
            String content = new String(msgBytes, "UTF-8");
            Log.i("TAG11", "收到PUSH透传消息,消息内容为:" + content);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public void onPushState(Context context, boolean pushState) {
        super.onPushState(context, pushState);
        Log.e("TAG11", "推送：onPushState");
    }

    @Override
    public void onPushMsg(Context context, byte[] msg, String token) {
        super.onPushMsg(context, msg, token);
        Log.e("TAG11", "推送：onPushMsg11");
    }

    @Override
    public void onToken(Context context, String token) {
        super.onToken(context, token);
        Log.e("TAG11", "推送：onToken");
    }

    @Override
    public void onToken(Context context, String token, Bundle extras) {
        super.onToken(context, token, extras);
        Log.e("TAG11", "推送：onToken111");
    }
}
